import carList from './components/carList.vue'
export default {
	components: {
		carList
	},
	data() {
		return {
			pageLoading: false,
			isHeight: 0,
			navHight: 0,
			isShow: false,
			specifAll: {},
			//车源列表
			carlist: [],
			// 面包屑
			history: {
				brand: ''
			},
			searchKey: '', //搜索历史关键字
			type: 0,
			iconSearch: '',
			/*一成首付*/
			paymentValue: 0,
			isOpen: false,
			//1成智能排序（通用）
			paymentsSort: [{
					id: 0,
					name: '智能排序'
				},
				{
					id: 1,
					name: '首付最低'
				},
				{
					id: 2,
					name: '月供最低'
				},
			],
			brandId: '', //品牌id
			carIndex: 1, //当前页
			loadStatus: '',
		}
	},
	onShow() {
		uni.$on('specifAll', data => {
			Object.assign(this.specifAll, data)

			this.history.brand = this.specifAll.brandlist.brand
			this.brandId = this.specifAll.brandlist.bid
			this.carIndex = 1
			this.carlist = []
			this.off()
			this.buyHome()
		})
	},
	created() {
		this.buyHome()
	},
	onReachBottom() {
		this.buyHome()
	},
	computed: {
		stickyHeight() {
			return Math.floor(Number(this.navHight) / (uni.upx2px(Number(this.navHight)) / Number(this.navHight))) - 1
		}
	},
	// onReady() {
	//   //获取导航栏高度

	//   const query = uni.createSelectorQuery().in(this)
	//   query.select('.nav').boundingClientRect(data => {
	//     // this.height = data.height
	//     this.navHight = data.height
	//   }).exec()
	// },
	methods: {
		more() {
			this.buyHome()
		},
		onPullDownRefresh() {
			// this.buyList()
			// this.$refs.refresh.buyList()
			this.buyHome()

		},
		// 加载前、中、后
		moreStatus(status) {
			this.loadStatus = status
		},
		//移除监听
		off() {
			uni.$off('specifAll')
		},

		//品牌直供
		async buyHome() {
			uni.showLoading({
				title: '加载中'
			})
			this.loadStatus = 'loading'
			try {
				let data = {
					'pageIndex': this.carIndex,
					'pageSize': 10,
					'brand_Id': String(this.brandId)
				}
				const res = await this.$api.buyCar.getBrandSupplyList(data)
				console.log(res)
				if (res.data.list.length === 0) {
					this.isShow = true
				}
				this.$nextTick(() => {
					this.pageLoading = true
				})
				this.carlist = [...this.carlist, ...res.data.list]
				uni.stopPullDownRefresh()
				if (res.data.total <= 10) {
					this.loadStatus = 'nomore'
				} else {
					this.moreStatus(res.data.list.length !== 0 ? 'loadmore' : 'nomore')
				}
				uni.hideLoading()
				if (res.data.list.length === 0) return false
				this.carIndex += 1 // 当前页加1
			} catch (e) {
				uni.stopPullDownRefresh()
				uni.hideLoading()
			}
		},
		delBrand() {
			//删除之后恢复默认
			this.carlist = []
			this.carIndex = 1
			this.brandId = ''
			this.history.brand = ''

			this.buyHome()
		},
		onNavigationBarButtonTap(url) {
			uni.navigateTo({
				url: '/pages_buy_index/choice_brand/choice_brand'
			})
		},
		//重置
		reset() {
			this.carlist = []
			this.carIndex = 1
			this.brandId = ''
			this.history.brand = ''
			this.buyHome()
		},
		//下拉关闭
		close(e) {
			this.isOpen = false

		},
		//下拉列表打开
		open(e) {
			this.isOpen = true

		},

	}
}